package com.earl.eatbao.util;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;

/**
 * <p>Title:SendCheckCodeUtil </p>
 * <p>Description:发送短信验证码的工具 </p>
 * <p>Company:Wteam </p> 
 *  @author Wteam 李焕滨 86571705@qq.com
 *  @date 2016年4月12日 下午9:27:40
 */
public class SendCheckCodeUtil {
	
	/**
	 * 访问地址
	 */
	private static final String URL = "http://gw.api.taobao.com/router/rest";
	/**
	 * 短信模板ID
	 */
	private static final String MESSAGE_MODEL_ID = "23347376";
	/**
	 * 阿里木鱼账户密钥
	 */
	private static final String KEY = "422e6b2eca79ed270e2210c8829cad1b";
	
	/**
	 * 发送短信验证码
	 * @throws ApiException 
	 */
	public static final AlibabaAliqinFcSmsNumSendResponse sendCheckCode(String teleNum,String checkCode) throws ApiException {
		
		if(teleNum == null || teleNum.length() != 11 || checkCode == null || "".equals(checkCode)) {
			throw new IllegalArgumentException("参数异常");
		}
		
		TaobaoClient client = new DefaultTaobaoClient(URL, MESSAGE_MODEL_ID,KEY);
		AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
		req.setSmsType("normal");
		req.setSmsFreeSignName("登录验证");
		req.setSmsParamString("{\"code\":\""+ checkCode +"\",\"product\":\"carkeeper\"}");
		req.setRecNum(teleNum);
		req.setSmsTemplateCode("SMS_7805638");
		
		return client.execute(req);
	}
}
